package com.gupao.strategy.promotion;

import java.util.HashMap;
import java.util.Map;

/**
 * 结合工厂模式
 */
public class PromotionActivityFactory {
    private static Map<String, PromotionStrategy> promotionStrategyMap = new HashMap<String, PromotionStrategy>();
    static{
        promotionStrategyMap.put(PromotionConstance.CASH_BACK, new CashBackStrategy());
        promotionStrategyMap.put(PromotionConstance.COUPON, new CouponStrategy());
        promotionStrategyMap.put(PromotionConstance.EMPTY, new EmptyStrategy());
    }
    private PromotionActivityFactory(){}

    public static PromotionStrategy getInstance(String promotionKey){
        PromotionStrategy promotionStrategy = promotionStrategyMap.get(promotionKey);
        return  promotionStrategy == null ? promotionStrategyMap.get(PromotionConstance.EMPTY) : promotionStrategy;
    }

    class PromotionConstance{
        public static final String CASH_BACK = "返现";
        public static final String COUPON = "优惠券";
        public static final String EMPTY = "无优惠";
    }
}
